/**
 * 书籍部分数据表
 */

const { Sequelize, Model } = require('sequelize')
const { sequelize } = require('@core/db.js')
const axios = require('axios')
const { BookConfig } = require('@config')

class Book extends Model {
  static async getDetail (date) {
    const book = await axios.get(BookConfig.detailUrl, {
      params: {
        key: BookConfig.key,
        keyword: date
      }
    })
    return book.data
  }
}

Book.init({
  id: {
    type: Sequelize.STRING,
    primaryKey: true
  },
  fav_nums: {
    type: Sequelize.INTEGER,
    defaultValue: 0
  },
  type: Sequelize.INTEGER
}, {
  sequelize,
  tableName: 'book'
})

module.exports = {
  Book
}